<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>战士</button>
    <button>法师</button>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
    <script>
        const btns = document.querySelectorAll('button');
        btns[0].onclick = async function () {
            try {
                let response = await axios({
                    method: 'get',
                    url: 'http://api.xiaohigh.com/lol',
                    params: {
                        q: '战士'
                    },
                    // 配置请求头
                    headers: {
                        name: 'aaa'
                    }
                })

                console.log(response);
            } catch (error) {
                console.log(error.message);
            }
        }


        // 针对axios发出的所有请求的配置 ==> 指定默认配置
        //  axios.defaults.属性名= 属性值
        //  baseURL: 基础路径
        //  timeout: 超时时间  1000*3
        axios.defaults.baseURL='http://api.xiaohigh.com';
        axios.defaults.timeout=1000*2;
        btns[1].onclick = async function () {
            try {
                let response = await axios({
                    method: 'get',
                    url: '/lol?name=盖伦',
                    // params: {
                    //     q: '法师'
                    // },
                    // 配置请求头
                    headers: {
                        name: 'bbb'
                    }
                })

                console.log(response);
            } catch (error) {
                console.log(error.message);
            }
        }


    </script>
</body>

</html>